-
-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow a percent_max to be specified in ingredients Fixes #5369 #7639
Conversation
lib/ProductOpener/Ingredients.pm
Outdated
@@ -2532,9 +2533,16 @@ sub init_percent_values ($total_min, $total_max, $ingredients_ref) { | |||
$ingredient_ref->{percent_min} = 0; | |||
} | |||
if ((not defined $ingredient_ref->{percent_max}) or ($ingredient_ref->{percent_max} > $total_max)) { | |||
$ingredient_ref->{percent_max} = $total_max; | |||
my $value = get_inherited_property("ingredients", $ingredient_ref->{id}, "percent_max:en"); | |||
if (defined $value and $index > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not construct a test case where it made a difference, but I'd feel safer if we also tested that $value < $total_max
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test case although it didn't fail without the guard, but added the guard too anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @john-gom , thanks a lot for the PR. Looks good to me, I just have 2 minor suggestions.
Co-authored-by: Stéphane Gigandet <stephane@openfoodfacts.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
Have made some more changes to limit the "blast radius" of this change, so percent_max will not be applied in the following scenarios:
|
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
Getting a problem with perltidy on Windows:
What
Add a percent_max property to ingredients taxonomy so for ingredients that are never more than a certain percentage, unless they are the main ingredient
Related issue(s) and discussion